package com.cqust.icc.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import static com.cqust.icc.aspect.AddLog.extracted;

@Component
@Aspect
public class MyAdvice {

    //切点
    @Pointcut("execution( * com.cqust.icc.biz.CardBiz.*(..))")
    public void pointCut() {
    }

    //前置通知
    @Before("pointCut()")
    public void before(JoinPoint joinPoint) {
        String method_name =  joinPoint.getSignature().getName();
        extracted(method_name);

//        System.out.print("这是前置通知！");
//        System.out.print("目标类是：" + joinPoint.getTarget());
//        System.out.println(",被织入增强处理的目标方法为：" +
//                joinPoint.getSignature().getName());
    }



    //返回通知
    @AfterReturning("pointCut()")
    public void afterReturning(JoinPoint joinPoint) {
//        System.out.print("这是返回通知!");
//        System.out.println("被织入增强处理的目标方法为：" +
//                joinPoint.getSignature().getName());
    }

    //环绕通知
    @Around("pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
//        System.out.println("这是环绕通知之前的部分！");
        //调用目标方法
        Object object = point.proceed();
//        System.out.println("这是环绕通知之后的部分！");
        return object;
    }

    //异常通知
    @AfterThrowing("pointCut()")
    public void afterException() {
//        System.out.println("异常通知");
    }

    //后置通知
    @After("pointCut()")
    public void after() {
//        System.out.println("这是后置通知！");
    }
}
